package com.yhd.controller;

import com.yhd.entity.dto.BrowseRecordDto;
import com.yhd.entity.dto.CourseBookedDto;
import com.yhd.entity.dto.CourseDto;
import com.yhd.entity.dto.CourseScheduleDetailDto;
import com.yhd.entity.query.BrowseRecordVO;
import com.yhd.entity.query.CourseBookedVO;
import com.yhd.entity.query.CourseScheduleDetailVO;
import com.yhd.entity.query.CourseVO;
import com.yhd.entity.result.ResultVo;
import com.yhd.model.ResultPage;
import com.yhd.service.CourseBookedService;
import com.yhd.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(value = "课程管理")
@Slf4j
@RequestMapping(value = "/course")
@CrossOrigin
public class CourseController extends WebBaseController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private CourseBookedService courseBookedService;



    @ApiOperation(value = "获取课程/活动/师资列表", notes = "获取课程/活动列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型 activity:活动，course:课程, team：师资", required = true, paramType = "字符串"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int")})
    @GetMapping("/list")
    @ResponseBody
    public ResultVo<ResultPage<List<CourseDto>>> selectCourseList(CourseVO courseVO){
        ResultPage<List<CourseDto>> resultPage = courseService.selectCourseList(courseVO);
        return ResultVo.success(resultPage);
    }

    @ApiOperation(value = "获取课程详情", notes = "获取课程详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "课程/活动/师资id", required = true, paramType = "字符串")})
    @GetMapping("/info")
    @ResponseBody
    public ResultVo<CourseDto> selectCourseInfo(CourseVO courseVO){
        CourseDto courseDto = courseService.selectCourseInfo(courseVO);
        return ResultVo.success(courseDto);
    }

    @ApiOperation(value = "新增课程/活动/师资", httpMethod = "POST", notes = "{\n" +
            "  \"name\": \"标题\",\n" +
            "  \"title\": \"简介\",\n" +
            "  \"cover\": \"cover\",\n" +
            "  \"imgs\": \"banner图片逗号隔开\",\n" +
            "  \"type\": \"类型 activity:活动，course:课程\",\n" +
            "  \"price\": \"价格\",\n" +
            "  \"limitStuNum\": \"限制的学员数量\",\n" +
            "  \"sellBeginTime\": \"开售开始时间\",\n" +
            "  \"sellEndTime\": \"开售结束时间\",\n" +
            "  \"classifyId\": \"分类ID\",\n" +
            "  \"ability\": \"课程权益，多个用逗号分隔\",\n" +
            "  \"courseList\": [\n" +
            "    {\n" +
            "      \"id\": \"活动关联课程集合传课程id\"\n" +
            "    }\n" +
            "  ],\n" +
            "  \"teamId\":\" 关联师资ID\"\n" +
            "  \"content\": \"老师介绍\",\n" +
            "  \"status\": \"状态 1:生效 0:未生效 2:下架\"\n" +
            "  \"latitude\": \"纬度\"\n" +
            "  \"longitude\": \"经度\"\n" +
            "  \"address\": \"详细地址\"\n" +
            "}")
    @PostMapping("/add")
    @ResponseBody
    public ResultVo<CourseDto> addCourse(@RequestBody CourseVO courseVO) {
        CourseDto courseDto = courseService.addCourse(courseVO,getUserInfo(request));
        if (null != courseDto){
            return ResultVo.success(courseDto);
        }
        return ResultVo.failure("10003","操作失败。");
    }

    @ApiOperation(value = "修改课程/活动/师资", httpMethod = "PUT", notes = "{\n" +
            "  \"id\": \"课程、活动id\",\n" +
            "  \"name\": \"标题\",\n" +
            "  \"title\": \"简介\",\n" +
            "  \"cover\": \"cover\",\n" +
            "  \"imgs\": \"banner图片逗号隔开\",\n" +
            "  \"price\": \"价格\",\n" +
            "  \"limitStuNum\": \"限制的学员数量\",\n" +
            "  \"sellBeginTime\": \"开售开始时间\",\n" +
            "  \"sellEndTime\": \"开售结束时间\",\n" +
            "  \"classifyId\": \"分类ID\",\n" +
            "  \"ability\": \"课程权益，多个用逗号分隔\",\n" +
            "  \"courseList\": [\n" +
            "    {\n" +
            "      \"id\": \"活动关联课程集合传课程id\"\n" +
            "    }\n" +
            "  ],\n" +
            "  \"teamId\": \"师资关联\",\n" +
            "  \"content\": \"老师介绍\",\n" +
            "  \"status\": \"状态 1:生效 0:未生效 2:下架\"\n" +
            "  \"latitude\": \"纬度\"\n" +
            "  \"longitude\": \"经度\"\n" +
            "  \"address\": \"详细地址\"\n" +
            "}")
    @PutMapping("/update")
    @ResponseBody
    public ResultVo<CourseDto> updateCourse(@RequestBody CourseVO courseVO) {
        CourseDto courseDto = courseService.updateCourse(courseVO,getUserInfo(request));
        if (null != courseDto){
            return ResultVo.success(courseDto);
        }
        return ResultVo.failure("10003","操作失败。");
    }


    @ApiOperation(value = "批量课程/活动上架", httpMethod = "POST", notes = "[\n" +
            "  {\n" +
            "    \"id\": \"活动关联课程集合传课程id\"\n" +
            "  },\n" +
            "  {\n" +
            "    \"id\": \"活动关联课程集合传课程id\"\n" +
            "  }\n" +
            "]")
    @PostMapping("/updateUp")
    @ResponseBody
    public ResultVo<Boolean> updateCourseUp(@RequestBody List<CourseVO> courseVOList) {
        //上架
        boolean updateCourseUp = courseService.updateCourseStatus(courseVOList, 1,getUserInfo(request));
        if (updateCourseUp){
            return ResultVo.success(updateCourseUp);
        }
        return ResultVo.failure("10003","操作失败。");
    }
    @ApiOperation(value = "批量课程/活动下架", httpMethod = "POST", notes = "[\n" +
            "  {\n" +
            "    \"id\": \"活动关联课程集合传课程id\"\n" +
            "  },\n" +
            "  {\n" +
            "    \"id\": \"活动关联课程集合传课程id\"\n" +
            "  }\n" +
            "]")
    @PostMapping("/updateDown")
    @ResponseBody
    public ResultVo<Boolean> updateDown(@RequestBody List<CourseVO> courseVOList) {
        //上架
        boolean updateCourseUp = courseService.updateCourseStatus(courseVOList, 2,getUserInfo(request));
        if (updateCourseUp){
            return ResultVo.success(updateCourseUp);
        }
        return ResultVo.failure("10003","操作失败。");
    }

   @ApiOperation(value = "删除课程/活动", httpMethod = "DELETE", notes = "{\n" +
            "  \"id\": \"e4d59eafcb8844a6bd1983db8fc6fdb0\"\n" +
            "}")
    @DeleteMapping("/delete")
    @ResponseBody
    public ResultVo<Boolean> deleteCourse(@RequestBody CourseVO courseVO) {
       Boolean deleteCourse = courseService.deleteCourse(courseVO,getUserInfo(request));
        if (deleteCourse){
            return ResultVo.success(deleteCourse);
        }
        return ResultVo.failure("10003","操作失败。");
    }


    @ApiOperation(value = "获取全部课程列表", notes = "获取全部课程列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型 activity:活动，course:课程", required = true, paramType = "字符串")})
    @GetMapping("/allCourse")
    @ResponseBody
    public ResultVo<List<CourseDto>> selectAllCourseList(CourseVO courseVO){
        List<CourseDto> resultPage = courseService.selectAllCourseList(courseVO);
        return ResultVo.success(resultPage);
    }

    @ApiOperation(value = "获取课程排课列表", notes = "获取课程排课列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "courseId", value = "课程Id", required = true, paramType = "字符串"),
            @ApiImplicitParam(name = "year", value = "年", required = false, paramType = "字符串"),
            @ApiImplicitParam(name = "month", value = "月", required = false, paramType = "字符串")})
    @GetMapping("/courseScheduleList")
    @ResponseBody
    public ResultVo<List<CourseScheduleDetailDto>> selectCourseScheduleList(CourseScheduleDetailVO courseScheduleDetailVO){
        List<CourseScheduleDetailDto> resultPage = courseService.selectCourseScheduleList(courseScheduleDetailVO);
        return ResultVo.success(resultPage);
    }

    @ApiOperation(value = "新增/修改课程排课", httpMethod = "POST", notes = "{\n" +
            "  \"id\": \"排课id 修改不能为空\",\n" +
            "  \"courseId\": \"课程id\",\n" +
            "  \"startTime\": \"课时开始时间 2021-05-24 08:00:00\",\n" +
            "  \"endTime\": \"课时结束时间 2021-05-24 09:00:00\",\n" +
            "  \"remarks\": \"备注\"\n" +
            "}")
    @PostMapping("/putCourseSchedule")
    @ResponseBody
    public ResultVo<CourseScheduleDetailDto> putCourseSchedule(@RequestBody CourseScheduleDetailVO courseScheduleDetailVO) {
        ResultVo<CourseScheduleDetailDto> resultVo = courseService.putCourseSchedule(courseScheduleDetailVO, getUserInfo(request));
        if (null != resultVo){
            return resultVo;
        }
        return ResultVo.failure("10003","操作失败。");
    }

    @ApiOperation(value = "删除课程排课", httpMethod = "DELETE", notes = "{\n" +
            "  \"id\": \"课程排课id\"\n" +
            "}")
    @DeleteMapping("/deleteCourseSchedule")
    @ResponseBody
    public ResultVo<Boolean> deleteCourseSchedule(@RequestBody CourseScheduleDetailVO courseScheduleDetailVO) {
        ResultVo<Boolean> resultVo = courseService.deleteCourseSchedule(courseScheduleDetailVO);
        if (null != resultVo){
            return resultVo;
        }
        return ResultVo.failure("10003","操作失败。");
    }

    @ApiOperation(value = "获取课程浏览用户列表", notes = "获取课程浏览用户列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "courseId", value = "课程Id", required = true, paramType = "字符串"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int")})
    @GetMapping("/courseBrowseList")
    @ResponseBody
    public ResultVo<ResultPage<List<BrowseRecordDto>>> selectCourseBrowseList(BrowseRecordVO browseRecordVO){
        ResultPage<List<BrowseRecordDto>> resultPage = courseService.selectCourseBrowseList(browseRecordVO);
        return ResultVo.success(resultPage);
    }

    @ApiOperation(value = "获取活动报名列表", notes = "获取活动报名列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "checkType", value = "0免费 1付款  不传全部", required = false, paramType = "字符串"),
            @ApiImplicitParam(name = "courseId", value = "活动id", required = false, paramType = "字符串"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int")})
    @GetMapping("/activityOrderList")
    @ResponseBody
    public ResultVo<ResultPage<List<CourseBookedDto>>> selectActivityOrderList(CourseBookedVO courseBookedVO){
        ResultPage<List<CourseBookedDto>> resultPage = courseBookedService.selectActivityOrderList(courseBookedVO);
        return ResultVo.success(resultPage);
    }


    @ApiOperation(value = "获取课程约课列表", notes = "获取课程约课列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "courseId", value = "课程id", required = true, paramType = "字符串"),
            @ApiImplicitParam(name = "courseSchId", value = "排课id", required = true, paramType = "字符串"),
            @ApiImplicitParam(name = "checkType", value = "0未预约 1已预约  不传全部", required = false, paramType = "字符串"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int")})
    @GetMapping("/courseSchList")
    @ResponseBody
    public ResultVo<ResultPage<List<CourseBookedDto>>> selectCourseSchList(CourseBookedVO courseBookedVO){
        ResultPage<List<CourseBookedDto>> resultPage = courseBookedService.selectCourseSchList(courseBookedVO);
        return ResultVo.success(resultPage);
    }
}
